var fs = require('fs');
var path = require('path');
var webpack = require('webpack');

var DEBUG = process.env.NODE_ENV === 'DEBUG';
console.log( process.env.NODE_ENV || 'BUILDING BEGINS');
console.log( DEBUG );
var serverEntry = DEBUG ? [
	'webpack-dev-server/client?http://localhost:3000',
	'webpack/hot/only-dev-server'
] : [];

var config = {
	entry : {
		'dev-1' : serverEntry.concat('./src/dev-1.js'),
		'dev-2' : serverEntry.concat('./src/dev-2.js')
	},
	output : {
		path : path.join( __dirname, 'dist' ),
		filename : '[name].bundle.js',
		publicPath : '/dist/'
	},
	module: {
		loaders: [
		  {
		    test: /\.js$/,
		    exclude: /node_modules/,
		    loader: 'babel-loader',
		    query: {
		      presets: ['react','es2015']
		    }
		  }
		]
	},
	plugins: [
		(DEBUG
			? new webpack.HotModuleReplacementPlugin()
			: new webpack.optimize.UglifyJsPlugin() 
		),		
		new webpack.NoErrorsPlugin()
	]
};

module.exports = config;